//package org.com.ashen.web.voice.demo;
//
//import java.io.IOException;
//import java.text.SimpleDateFormat;
//import java.util.*;
//
//import cn.emay.http.client.HttpClient;
//import cn.emay.http.client.common.HttpHeader;
//import cn.emay.http.client.common.HttpResultCode;
//import cn.emay.http.client.response.HttpResponse;
//import com.google.gson.reflect.TypeToken;
//
//import org.com.ashen.web.voice.common.http.client.EmayHttpClient;
//import org.com.ashen.web.voice.dto.MobileAndVariableDTO;
//import org.com.ashen.web.voice.request.*;
//import org.com.ashen.web.voice.response.VoiceResponse;
//import org.com.ashen.web.voice.util.AES;
//import org.com.ashen.web.voice.util.GZIPUtils;
//import org.com.ashen.web.voice.util.JsonHelper;
//
//public class TestAESInterface {
//
//	private static EmayHttpClient httpClient = new EmayHttpClient();
//
//	public static void main(String[] arg) {
//		String appId = "EUCP-EMY-VOC0-CQ4E6";
//		String secretKey = "104B0DF9E0AA645F";
////		String host = "http://127.0.0.1:8999";
//		String host = "http://voice.b2m.cn:80";
//		String templateId = "1631516415074002000";
//		try {
//			// 获取余额
//			// getVoiceBalanceSecure(appId, secretKey, host, "/voice/secure/getBalance");
//			// getVoiceBalanceSecure(appId, secretKey, host, "/join/secure/getBalance");
//
//			// 获取状态报告
//			// getVoiceReportSecure(appId, secretKey, host, "/voice/secure/getReport");
//			// getVoiceReportSecure(appId, secretKey, host, "/join/secure/getReport");
//
//			// 营销发送接口
//			// sendCollectSecure("EUCP-EMY-VOC1-1YZZC", "A91BC955EE907FB9", host, "/voice/secure/sendCTCode", "亿美你好！", "2018010709302911,2018010709302912", "15902010205,15903050206");
//
//			// 通知接口
//			// sendNotifySecure("EUCP-EMY-VOC1-2YZZR", "696CE880EF8A2EE0", host, "/voice/secure/send", "亿美你好！", "2018010709302911,2018010709302912", "15902010205,15903050206");
//
//			// 验证码接口
//			// sendVerifySecure("EUCP-EMY-VOC1-YJD42", "89FBA392348B5360", host, "/voice/secure/sendVFCode", "1111", "2018010709302913", "15902010205");
//
//			// 语音短信
//			String smsContent = "sms";
//			String connectTime = "10";
//			String triggerConditions = "3";
//			String keyContent = "4";
//			// sendInteractiveSecure(appId, secretKey, host, "/join/secure/send", "亿美你好！", "2018010709302914", "15902010205", keyContent, triggerConditions, smsContent, connectTime);
//
//			// 语音模板短信
//			 sendTemplateVoiceSecure(appId, secretKey, host, "/voice/secure/templateSend", templateId, "2018010709302921,2018010709302922", "13651949883,17701640768", "sms短信内容是快递到了", "3", "123", "1");
////			// 语音参数模板
////			List<MobileAndVariableDTO> variableDTOS = new ArrayList<>();
////			MobileAndVariableDTO dto = new MobileAndVariableDTO();
////			dto.setCustomVoiceId("122");
////			dto.setMobile("15902010205");
////			Map<String, String> variableMap = new HashMap<>();
////			variableMap.put("name", "张三");
////			variableMap.put("age", "12");
////			dto.setVariable(variableMap);
////			variableDTOS.add(dto);
////			sendTemplateVariableVoiceSecure(appId, secretKey, host, "/voice/secure/templateVariableSend", templateId, variableDTOS, smsContent, triggerConditions, connectTime, keyContent);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//
//	}
//
//	private static void sendTemplateVoiceSecure(String appId, String secretKey, String host, String url, String templateId, String customVoiceIds, String mobiles, String smsContent, String triggerConditions, String connectTime, String keyContent) throws IOException {
//		System.out.println("=============begin sendTemplateVoiceSecure==================");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//		String timestamp = sdf.format(new Date());
//		VoiceSendRequest params = new VoiceSendRequest();
//		params.setAppId(appId);
//		params.setTemplateId(templateId);
//		params.setCustomVoiceIds(customVoiceIds);
//		params.setMobiles(mobiles);
//		params.setTimestamp(timestamp);
//
//		params.setSmsContent(smsContent);
//		params.setTriggerConditions(triggerConditions);
//		params.setConnectTime(connectTime);
//		params.setKeyContent(keyContent);
//System.out.println(JsonHelper.toJsonString(params));
//		List<HttpHeader> headers = new ArrayList<HttpHeader>();
//		headers.add(new HttpHeader("appId", appId));
//		headers.add(new HttpHeader("gzip", "on"));
//		headers.add(new HttpHeader("encode", "UTF-8"));
//		String requestParameterJson = JsonHelper.toJsonStringWithoutNull(params);
//		System.out.println("requestParameterJson"+requestParameterJson+ "secretKey"+secretKey+"headers"+headers+"host + url"+host + url);
//
//		String json = requestAES(requestParameterJson, secretKey, headers, host + url);
//		if (json != null) {
//			@SuppressWarnings("unused")
//			VoiceResponse[] data = JsonHelper.fromJson(new TypeToken<VoiceResponse[]>() {
//			}, json);
//			System.out.println("sendTemplateVoiceSecure result: " + json);
//		}
//		System.out.println("=============end sendTemplateVoiceSecure==================");
//	}
//
//	private static void sendTemplateVariableVoiceSecure(String appId, String secretKey, String host, String url, String templateId, List<MobileAndVariableDTO> variableDTOS, String smsContent,
//			String triggerConditions, String connectTime, String keyContent) throws IOException {
//		System.out.println("=============begin sendTemplateVariableVoiceSecure==================");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//		String timestamp = sdf.format(new Date());
//		VoiceTemplateVariableRequest params = new VoiceTemplateVariableRequest();
//		params.setAppId(appId);
//		params.setTemplateId(templateId);
//		params.setVariables(variableDTOS);
//		params.setTimestamp(timestamp);
//		params.setSmsContent(smsContent);
//		params.setTriggerConditions(triggerConditions);
//		params.setConnectTime(connectTime);
//		params.setKeyContent(keyContent);
//
//		List<HttpHeader> headers = new ArrayList<HttpHeader>();
//		headers.add(new HttpHeader("appId", appId));
//		headers.add(new HttpHeader("gzip", "on"));
//		headers.add(new HttpHeader("encode", "UTF-8"));
//		String requestParameterJson = JsonHelper.toJsonStringWithoutNull(params);
//		String json = requestAES(requestParameterJson, secretKey, headers, host + url);
//		if (json != null) {
//			@SuppressWarnings("unused")
//			VoiceResponse[] data = JsonHelper.fromJson(new TypeToken<VoiceResponse[]>() {
//			}, json);
//			System.out.println("sendTemplateVoiceSecure result: " + json);
//		}
//		System.out.println("=============end sendTemplateVoiceSecure==================");
//	}
//
//	private static void sendInteractiveSecure(String appId, String secretKey, String host, String url, String voiceContent, String customJoinId, String mobiles, String keyContent,
//			String triggerConditions, String smsContent, String connectTime) throws IOException {
//		System.out.println("=============begin sendInteractiveSecure==================");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//		String timestamp = sdf.format(new Date());
//		VoiceInteractiveRequest params = new VoiceInteractiveRequest();
//		params.setAppId(appId);
//		params.setVoiceContent(voiceContent);
//		params.setCustomJoinId(customJoinId);
//		params.setMobiles(mobiles);
//		params.setKeyContent(keyContent);
//		params.setTriggerConditions(triggerConditions);
//		params.setSmsContent(smsContent);
//		params.setConnectTime(connectTime);
//
//		params.setTimestamp(timestamp);
//
//		List<HttpHeader> headers = new ArrayList<HttpHeader>();
//		headers.add(new HttpHeader("appId", appId));
//		headers.add(new HttpHeader("gzip", "on"));
//		headers.add(new HttpHeader("encode", "UTF-8"));
//		String requestParameterJson = JsonHelper.toJsonStringWithoutNull(params);
//		String json = requestAES(requestParameterJson, secretKey, headers, host + url);
//		if (json != null) {
//			@SuppressWarnings("unused")
//			VoiceResponse[] data = JsonHelper.fromJson(new TypeToken<VoiceResponse[]>() {
//			}, json);
//			System.out.println("sendInteractiveSecure result: " + json);
//		}
//		System.out.println("=============end sendInteractiveSecure==================");
//	}
//
//	private static void sendVerifySecure(String appId, String secretKey, String host, String url, String content, String customVoiceId, String mobile) throws IOException {
//		System.out.println("=============begin sendVerifySecure==================");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//		String timestamp = sdf.format(new Date());
//		VoiceSingleRequest params = new VoiceSingleRequest();
//		params.setAppId(appId);
//		params.setContent(content);
//		params.setCustomVoiceId(customVoiceId);
//		params.setMobile(mobile);
//		params.setTimestamp(timestamp);
//
//		List<HttpHeader> headers = new ArrayList<HttpHeader>();
//		headers.add(new HttpHeader("appId", appId));
//		headers.add(new HttpHeader("gzip", "on"));
//		headers.add(new HttpHeader("encode", "UTF-8"));
//		String requestParameterJson = JsonHelper.toJsonStringWithoutNull(params);
//		String json = requestAES(requestParameterJson, secretKey, headers, host + url);
//		if (json != null) {
//			@SuppressWarnings("unused")
//			VoiceResponse[] data = JsonHelper.fromJson(new TypeToken<VoiceResponse[]>() {
//			}, json);
//			System.out.println("sendVerifySecure result: " + json);
//		}
//		System.out.println("=============end sendVerifySecure==================");
//	}
//
//	private static void sendNotifySecure(String appId, String secretKey, String host, String url, String content, String customVoiceIds, String mobiles) throws IOException {
//		System.out.println("=============begin sendNotifySecure==================");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//		String timestamp = sdf.format(new Date());
//		VoiceSendRequest params = new VoiceSendRequest();
//		params.setAppId(appId);
//		params.setContent(content);
//		params.setCustomVoiceIds(customVoiceIds);
//		params.setMobiles(mobiles);
//		params.setTimestamp(timestamp);
//
//		List<HttpHeader> headers = new ArrayList<HttpHeader>();
//		headers.add(new HttpHeader("appId", appId));
//		headers.add(new HttpHeader("gzip", "on"));
//		headers.add(new HttpHeader("encode", "UTF-8"));
//		String requestParameterJson = JsonHelper.toJsonStringWithoutNull(params);
//		String json = requestAES(requestParameterJson, secretKey, headers, host + url);
//		if (json != null) {
//			@SuppressWarnings("unused")
//			VoiceResponse[] data = JsonHelper.fromJson(new TypeToken<VoiceResponse[]>() {
//			}, json);
//			System.out.println("sendNotifySecure result: " + json);
//		}
//		System.out.println("=============end sendNotifySecure==================");
//	}
//
//	private static void sendCollectSecure(String appId, String secretKey, String host, String url, String content, String customVoiceIds, String mobiles) throws IOException {
//		System.out.println("=============begin sendCollectSecure==================");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//		String timestamp = sdf.format(new Date());
//		VoiceSendRequest params = new VoiceSendRequest();
//		params.setAppId(appId);
//		params.setContent(content);
//		params.setCustomVoiceIds(customVoiceIds);
//		params.setMobiles(mobiles);
//		params.setTimestamp(timestamp);
//
//		List<HttpHeader> headers = new ArrayList<HttpHeader>();
//		headers.add(new HttpHeader("appId", appId));
//		headers.add(new HttpHeader("gzip", "on"));
//		headers.add(new HttpHeader("encode", "UTF-8"));
//		String requestParameterJson = JsonHelper.toJsonStringWithoutNull(params);
//		String json = requestAES(requestParameterJson, secretKey, headers, host + url);
//		if (json != null) {
//			@SuppressWarnings("unused")
//			VoiceResponse[] data = JsonHelper.fromJson(new TypeToken<VoiceResponse[]>() {
//			}, json);
//			System.out.println("sendCollectSecure result: " + json);
//		}
//		System.out.println("=============end sendCollectSecure==================");
//	}
//
//	private static void getVoiceReportSecure(String appId, String secretKey, String host, String url) throws IOException {
//		System.out.println("=============begin getVoiceReportSecure==================");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//		String timestamp = sdf.format(new Date());
//		VoiceReportRequest params = new VoiceReportRequest();
//		params.setAppId(appId);
//		params.setTimestamp(timestamp);
//		List<HttpHeader> headers = new ArrayList<HttpHeader>();
//		headers.add(new HttpHeader("appId", appId));
//		headers.add(new HttpHeader("gzip", "on"));
//		headers.add(new HttpHeader("encode", "UTF-8"));
//		String requestParameterJson = JsonHelper.toJsonStringWithoutNull(params);
//		String json = requestAES(requestParameterJson, secretKey, headers, host + url);
//		System.out.println("getVoiceReportSecure result: " + json);
//		if (json != null) {
//			@SuppressWarnings("unused")
//			Map<String, Object>[] data = JsonHelper.fromJson(new TypeToken<Map<String, Object>[]>() {
//			}, json);
//			System.out.println("getVoiceReportSecure result: " + json);
//		}
//		System.out.println("=============end getVoiceReportSecure==================");
//	}
//
//	private static void getVoiceBalanceSecure(String appId, String secretKey, String host, String url) throws IOException {
//		System.out.println("=============begin getVoiceBalanceSecure==================");
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
//		String timestamp = sdf.format(new Date());
//		VoiceBaseRequest request = new VoiceBaseRequest();
//		request.setAppId(appId);
//		request.setTimestamp(timestamp);
//		List<HttpHeader> headers = new ArrayList<HttpHeader>();
//		headers.add(new HttpHeader("appId", appId));
//		headers.add(new HttpHeader("gzip", "on"));
//		headers.add(new HttpHeader("encode", "UTF-8"));
//		String requestParameterJson = JsonHelper.toJsonStringWithoutNull(request);
//		String json = requestAES(requestParameterJson, secretKey, headers, host + url);
//		System.out.println("balance: " + json);
//		System.out.println("=============end getVoiceBalanceSecure==================");
//	}
//
//	public static String requestAES(String requestParameterJson, String secretKey, List<HttpHeader> headers, String url) throws IOException {
//		HttpResponse response = null;
//		byte[] data = requestParameterJson.getBytes("UTF-8");
//		byte[] cData = GZIPUtils.compress(data);
//		byte[] aesData = AES.encrypt(cData, secretKey.getBytes("UTF-8"));
//		response = HttpClient.post(url, "utf-8", headers, null, aesData);
//		if (response.getResultCode().getCode().equals(HttpResultCode.SUCCESS.getCode())) {
//			List<HttpHeader> rheaders = response.getHeaders();
//			String code = null;
//			for (HttpHeader header : rheaders) {
//				if (header.getName() != null && header.getName().equals("result")) {
//					code = header.getValue();
//					break;
//				}
//			}
//			if (code.equals("SUCCESS")) {
//				byte[] decData = AES.decrypt(response.getData(), secretKey.getBytes("UTF-8"));
//				byte[] dcData = GZIPUtils.decompress(decData);
//				String resultJson = new String(dcData, "UTF-8");
//				System.out.println("resultCode: " + code);
//				return resultJson;
//			} else {
//				System.out.println("resultCode: " + code);
//				return "";
//			}
//
//		}
//		return null;
//	}
//
//}
